package test2;

import java.util.ArrayList;
import java.util.Scanner;

public class test2_8 {
	public static void main(String[] agrs){
		Scanner sr=new Scanner(System.in);
		ArrayList<String> strlist=new ArrayList<String>();
		String e="!!end!!";
		String a=sr.next();
		strlist.add(a);
		while(!a.equals(e)){
			a=sr.next();
			strlist.add(a);
		}
		strlist.remove(strlist.size()-1);
		strlist.add(0,"begin");
		strlist.add("end");
		System.out.println(strlist);
		String str=sr.next();
		if(strlist.contains(str)){
			System.out.println("true");
			System.out.println(strlist.indexOf(str));
		}
		else
			System.out.println("false");
		System.out.println(strlist.lastIndexOf(str));
		//System.out.println(strlist.get(0));
		System.out.println(strlist.remove(0));
		System.out.println(strlist);
		str=sr.next();
		strlist.set(1,str);
		System.out.println(strlist);
		str=sr.next();
		ArrayList<String> strlist1=new ArrayList<String>();
		int i=0;
		int size=strlist.size();
		for(i=0;i<size;i++){
			String p=(String)strlist.get(i);
			if(p.indexOf(str)!=-1)
				strlist1.add(p);
		}
		System.out.println(strlist1);
		strlist.remove(str);
		System.out.println(strlist);
		strlist.clear();
		System.out.println(strlist+","+strlist.size()+","+strlist.isEmpty());
	}

}
